import Vue from 'vue'
import VueRouter from 'vue-router'
import Mainview from '../views/MainView.vue'
import SearchView from '../views/SearchView.vue'
import DetailView from '../views/DetailView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'search_ans'
},
  {
    path: '/home',
    name: 'home',
    component: Mainview,
    meta:{title:'布尔引擎', changeTitle: true}
  },
  {
    name:'search_ans',
    path:'/search_ans',
    component:SearchView,
    meta:{title:'搜索结果', changeTitle: true}
  },
  {
    name:'detail',
    path:'/detail',
    component:DetailView,
    meta:{title:'详情展示', changeTitle: true}
  }
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//更新网页标题
router.afterEach((to) => {
  if (to.meta.changeTitle) {
      document.title = to.meta.title ;
  }
})
export default router
